home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
- Subject: Re: Undefined behavior? on type conversion, was: Re: Hungarian notation
- Date: Sat, 03 Feb 1996 15:21:34 GMT
- Organization: Netcom
- Message-ID: <31137427.133220928@nntp.ix.netcom.com>
- References: <30C40F77.53B5@swsbbs.com> <4d2ok0$69s@beach.and.nl> <4er2qo$h2s@galaxy.ucr.edu> <31118641.6802368@nntp.ix.netcom.com> <4eurpq$b75@news.xmission.com>
- NNTP-Posting-Host: ix-dc11-06.ix.netcom.com
- X-NETCOM-Date: Sat Feb 03 7:21:26 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- tknarr@xmission.com ( Todd Knarr ) wrote:
-
- > In <31118641.6802368@nntp.ix.netcom.com>, miker3@ix.netcom.com (Mike Rubenstein) writes:
- > >> : |> Repeating the quote from ISO 6.2.1.2
- > >> :
- > >> : |> When a value with integral type is demoted to a signed integer
- > >> : |> with smaller size or an unsigned integer is converted to its
- > >> : |> corresponding signed integer, if the value cannot be
- > >> : |> represented the result is implementation defined.
- >
- > >Consider a machine with 8 bit char and the expression
- > >
- > > (char) 256
- > >
- > >Here we have correct syntax and correct data. The standard says that
- > >this converts the number 256 to a char. I believe I have a right to
- > >assume that this will be done.
- >
- > Except that 6.2.1.2 says you can't assume that. Your particular
- > implementation may let you assume that, but the standard doesn't
- > require it to. On machines with the capability of extracting the
- > low-order bits the reasonable thing to do would be to fill in the
- > char with the low-order byte ( 0 in your example ), but the
- > standard doesn't say the machine has to have that capability, or
- > that the implementation has to excercise it, or that the implementation
- > has to be reasonable. As I asked before, do you think that, on a
- > machine where the natural hardware response to your example would be
- > a machine check and system halt, the committee intended to require
- > that the compiler insert a range check before every such conversion?
- >
- > As for "result" vs. "behavior", while I don't have the standard in
- > front of me I believe that in the case of the ++ and -- operators the
- > side-effect increment and decrement is also referred to as a result.
- > If that is so, then their use of "result" doesn't rule out side-effects
- > in the conversion, which can be anything since the implementation gets
- > to define them.
- >
- > Can you tell I tend to read the standard conservatively? I've been
- > burned once too often by assuming things that weren't explicitly
- > spelled out.
-
- No, I can't tell that you read the standard conservatively. You seem
- to be adding things that just aren't there. You're saying that
- although the standard says that a construction converts one value to
- another and I use the construction correctly, with correct data, the
- implementation is not required to convert one value to the other and,
- in fact, is not required to even execute later instructions.
-
- To make things perfectly clear, I believe that the standard requires
- this of a conforming implementation even if the underlying hardware
- does not directly support it.
-
- The standard does not say that a machine must have the ability to do
- multiplication either. That doesn't mean that an implemenation can
- simply give an exception if you do a multiplication -- it must handle
- it in software since the standard requires a C implementation be able
- to do multiplication.
-
- I'm afraid that I can't find where the standard refers to the
- side-effect of incrementing. Of course the standard is pretty large
- and I'm afraid I don't have the time to check it completely. 6.3.3.1
- clearly uses the word "result" only to refer to the value:
-
- The value of the operand of the prefix ++ operator is
- incremented. The result is the new value of the operand after
-
- incrementation.
-
- Perhaps your memory is faulty. I'd suggest getting a copy of the
- standard and using that, rather than your memory, to justify your
- position.
-
-
- Michael M Rubenstein
-